<%@page import="algorithm.KNearestNeighbourModel"%>
<%@page import="algorithm.KNearestNeighbour"%>
<%@page import="utility.InstancesConverter"%>
<%@page import="algorithm.DecisionTreeModel"%>
<%@page import="algorithm.DecisionTree"%>
<%@page import="algorithm.NaiveBayesianModel"%>
<%@page import="algorithm.NaiveBayesian"%>
<%@page import="weka.core.Instances"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%

  String type = (String) request.getParameter("type");
  String algorithm = (String) request.getParameter("algorithm");
  session.setAttribute("type", type);
  session.setAttribute("algorithm", algorithm);
  
  Instances data = (Instances)session.getAttribute("dataset");
  
  if (algorithm.equals("ori")) {
    if (type.equals("nb")) {
      NaiveBayesian nb = new NaiveBayesian();
      NaiveBayesianModel nbm = nb.NaiveBayesWEKA(data);
      session.setAttribute("model", nbm);
    } else if (type.equals("dt")) {
      DecisionTree dt = new DecisionTree();
      DecisionTreeModel dtm = dt.DecisionTreeWEKA(data);
      session.setAttribute("model", dtm);        
    } else {
      KNearestNeighbour knn = new KNearestNeighbour();
      KNearestNeighbourModel knnm = knn.KNearestNeighbourWEKA(data);
      session.setAttribute("model", knnm);  
    }
  } else {
    if (type.equals("nb")) {
      NaiveBayesian nb = new NaiveBayesian();
      NaiveBayesianModel nbm = nb.generateModel(data);
      session.setAttribute("model", nbm);
    } else if (type.equals("dt")) {
      DecisionTree dt = new DecisionTree();
      DecisionTreeModel dtm = dt.generateModel(InstancesConverter.convert(data));
      session.setAttribute("model", dtm);   
    } else {
      KNearestNeighbour knn = new KNearestNeighbour();
      KNearestNeighbourModel knnm = knn.generateModel(data, 3);
      session.setAttribute("model", knnm);  
    }
    
    
  }
  response.sendRedirect("classification.jsp");
%>